package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.service.BeanWelfareService;
import com.juyu.miliao.common.domain.Subject;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: BeanWelfareController
 * @Description: TODO
 * @Author zhangcheng
 * @Date 19-9-18上午11:25
 */
@RestController
public class BeanWelfareController {
    @Resource
    private BeanWelfareService beanWelfareService;

    @GetMapping("/beanWelfare/statuses")
    public List<Integer> getBeanWelfare(Authentication token) {
        Subject subject = (Subject) token.getPrincipal();
        long userId = subject.getId();
        return beanWelfareService.getBeanWelfare(userId);
    }

    @PostMapping("/beanWelfare/award")
    public void award(Authentication token, @RequestParam("rewardId") Long rewardId) {
        Subject subject = (Subject) token.getPrincipal();
        long userId = subject.getId();
        beanWelfareService.award(userId, rewardId);
    }

}
